package com.example.back.controller;

import com.example.back.model.User;
import com.example.back.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @author : 贾媛晴
 * @createTime : 2022/4/25 14:52
 */
@RestController
@Api(tags = "UserController")
@CrossOrigin //允许跨域
//@RequestMapping("/user")
@SessionAttributes({"logUser"})
public class UserController {

    @Autowired
    UserService userService;

    @ApiOperation("用户登录")
    @GetMapping("/loginUser")
    public User login(String username,String password) {
        User user=this.userService.selectForLogin(username,password);
        return user;

//        if (user != null) {
//            return user;
//        }else {
//            return null;
//        }
    }

    @ApiOperation("用户注册")
    @GetMapping("/registered")
    public int insertUser(String username,String password){
        return this.userService.insertUser(username,password);
    }
}
